﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.App_Code;
using QXBook.Utils;
using QXBook.Service;
using QXBook.Model;

namespace Web.SysManage.Orders
{
    public partial class Shipment : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.TextBind();
            }
            btnSave.Click += new EventHandler(btnSave_Click);
        }

        protected void TextBind()
        {
            string headerID = CommonUtils.Get("HeaderID");
            if (!string.IsNullOrEmpty(headerID))
            {
                hHeaderID.Value = headerID;
                OrderHeaderInfo order = ServiceFactory.CreateInstance<OrderService>().GetOrderByOrderID(CommonUtils.ToInt(hHeaderID.Value));

                if (order != null)
                {
                    iOrderCode.Value = order.OrderCode;
                }
            }
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            this.Save();
        }

        protected void Save()
        {
            OrderHeaderInfo order = ServiceFactory.CreateInstance<OrderService>().GetOrderByOrderID(CommonUtils.ToInt(hHeaderID.Value));
            if (order != null)
            {
                if (order.IsPayroll != YesNo.Yes)
                {
                    ResponseErch("改订单还没支付");
                    return;
                }
                order.LogisticsCompany = iLogisticsCompany.Value;
                order.LogisticsNum = iLogisticsNum.Value;
                order.Fare = CommonUtils.ToDecimal(iFare.Value);
                order.Remark = taRemark.Value;
                order.IsShipments = YesNo.Yes;
                ServiceFactory.CreateInstance<OrderService>().UpdateOrder(order);
            }
        }
    }
}